export default {
  namespaced: true,
  state: {
    title: '',
    istoggleAll: true,
    cartlists: JSON.parse(localStorage.carts || ' []')
  },
  mutations: {
    POST_DATE(state, payload) {
      state.cartlists = payload
    },
    DEL(state, pay) {
      console.log(pay)
      state.cartlists.forEach((el, index) => {
        if (pay === el.id) {
          state.cartlists.splice(index, 1)
          localStorage.carts = JSON.stringify(state.cartlists || '[]')
        }
      })
    }

  },
  actions: {

  },
  getters: {
    getAllPrice(state) {
      let o = 0
      state.cartlists.forEach(item => {
        if (item.isShow) {
          o += item.count * item.price
        }
      })
      return o
    },
    getAllCount(state) {
      let c = 0
      state.cartlists.forEach(item => {
        if (item.isShow) {
          c += item.count
        }
      })
      return c
    }
  }
}